package com.wangshb.upms.generate.generate;

import com.wangshb.upms.generate.Configuration;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 创建java代码
 */
public class EditRequestDtoGenerate extends AbstractGenerate {


    public EditRequestDtoGenerate(Configuration configuration) {
        super(configuration);
    }

    @Override
    public File getFile() {

        Configuration configuration = getConfiguration();

        //1. 创建java - entity 代码
        String tableName = configuration.getTableEntity().getTableName();
        String entityParentPath = configuration.getJavaSrcPath() + "\\" + configuration.getPackageName().replaceAll("\\.", "\\\\") + "\\dto\\" + tableName.substring(0, tableName.indexOf("_")) +
                "\\" + replaceUnderLineAndUpperCase(tableName.substring(tableName.indexOf("_") + 1), true);
        File dirFile = new File(entityParentPath);
        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }
        return new File(dirFile.getAbsolutePath() + "\\" + configuration.getTableEntity().getEntityName() + "EditRequestDto.java");
    }

    @Override
    public Map<String, Object> getTemplateParams() {
        String tableName = getConfiguration().getTableEntity().getTableName();
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("table_entity", getConfiguration().getTableEntity());
        dataMap.put("package_name", getConfiguration().getPackageName());
        dataMap.put("system_name", tableName.substring(0, tableName.indexOf("_")));
        dataMap.put("fun_name", replaceUnderLineAndUpperCase(tableName.substring(tableName.indexOf("_") + 1), true));
        dataMap.put("property_columns", getConfiguration().getTableEntity().getColumnPropertyList());
        return dataMap;
    }

    @Override
    public String getTemplateName() {
        return "templates/editRequestDto.ftl";
    }
}
